<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateLikeTbl extends Migrator
{
    const TBL_NAME = 'like';
    const RELATED_TBL_NAME = 'article';
    const RELATED_USER_TBL_NAME = 'user';


    public function change()
    {
        $table  =  $this->table(addTablePrefix(self::TBL_NAME),[
            'engine'=>'InnoDB',
            'comment' => '喜欢表',
            'signed' => false
        ]);

        $table
            ->addColumn('user_id', 'integer',array('signed' => false,'default'=>0,'comment'=>'用户'))
            ->addColumn('article_id', 'integer',array('signed' => false,'default'=>0,'comment'=>'文章'))
            ->addColumn('create_time', 'integer',array('signed' => false,'default'=>0,'comment'=>'创建时间'))
            ->addForeignKey('user_id', addTablePrefix(self::RELATED_USER_TBL_NAME), 'id', ['delete'=> 'CASCADE', 'update'=> 'NO_ACTION'])
            ->addForeignKey('article_id', addTablePrefix(self::RELATED_TBL_NAME), 'id', ['delete'=> 'CASCADE', 'update'=> 'NO_ACTION'])
            ->create();
    }
}
